﻿Public Class ctrTiepNhanNV

    Private Sub ctrTiepNhanNV_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        gvNhanVien_Load()
        cmbBangCap_Load()
        cmbChucVu_Load()
        rdNu.Checked = True
        txtHoTen.Select()
    End Sub

    Private Sub gvNhanVien_Load()
        Dim bus As NhanVienBUS = New NhanVienBUS()
        gvNhanVien.DataSource = bus.GetTable()
    End Sub

    Private Sub cmbBangCap_Load()
        Dim bus As BangCapBUS = New BangCapBUS()
        cmbBangCap.DataSource = bus.GetTable()
        cmbBangCap.DisplayMember = "TenBC"
        cmbBangCap.ValueMember = "MaBC"
    End Sub

    Private Sub cmbChucVu_Load()
        Dim bus As ChucVuBUS = New ChucVuBUS()
        cmbChucVu.DataSource = bus.GetTable()
        cmbChucVu.DisplayMember = "TenCV"
        cmbChucVu.ValueMember = "MaCV"
    End Sub

    Private Sub btnTiepNhan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTiepNhan.Click
        Dim tmp As NhanVienDTO = New NhanVienDTO()
        tmp.HoTen = txtHoTen.Text
        tmp.CMND = txtCMND.Text
        If (rdNam.Checked = True) Then tmp.GioiTinh = False Else tmp.GioiTinh = True
        tmp.NgaySinh = dtNgaySinh.Value.Date
        tmp.DiaChi = txtDiaChi.Text
        tmp.DienThoai = txtDienThoai.Text
        tmp.MaBC = cmbBangCap.SelectedValue.ToString()
        tmp.MaCV = cmbChucVu.SelectedValue.ToString()
        tmp.TinhTrang = True

        Dim bus As NhanVienBUS = New NhanVienBUS()
        bus.Insert(tmp)
        gvNhanVien_Load()
    End Sub

    Private Sub btnLamMoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLamMoi.Click
        txtHoTen.Text = ""
        txtDiaChi.Text = ""
        txtDienThoai.Text = ""
        txtCMND.Text = ""
        txtHoTen.Select()
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        frmMain.TabControl1.TabPages.Remove(frmMain.TabControl1.SelectedTab)
    End Sub

End Class
